﻿using System.IO;
using System.Windows;
using DesktopToy.Core.Common;
using YamlDotNet.Serialization;

namespace DesktopToyWpf.Services;

public class Storage
{
    public static Storage Load()
    {
        if (!File.Exists(PathHelper.GetResourcePath("Storage.yml")))
        {
            return new Storage();
        }
        
        var deserializer = new DeserializerBuilder().Build();
        var yaml = File.ReadAllText(PathHelper.GetResourcePath("Storage.yml"));
        return deserializer.Deserialize<Storage>(yaml);
    }
    
    public void Save()
    {
        var serializer = new SerializerBuilder().Build();
        var yaml = serializer.Serialize(this);
        File.WriteAllText(PathHelper.GetResourcePath("Storage.yml"), yaml);
    }

    public Point? WindowLocation; // 如果为 null 就是在窗口中间
    public double WindowWidth = 1000d;
    public double Dpi = 1d;
    
    public List<DayStorage> Days { set; get; } = [];
}


public class DayStorage
{
    public int Year;
    public int Month;
    public int Day;

    public List<Point> MoodPoints = [];
    public int HappyCount;
}